<template>
	<view id="app" @click="openMsg">
		<!-- 我的头部开始 -->
		<view class="wdmaintb oh plr30">
			<!-- 信息 -->
			<view class="rows mt30">
				<!-- 个人信息 -->
				<view class="col df oh f1 df aic" @click="login">
					<view class="wdmaintl wh110 avatar bw">
						<image :src="wrap.avatar ? wrap.avatar : '/static/no.png'" mode="aspectFill"></image>
					</view>
					<view class="login oh" v-if="!wrap.id">
						<text class="ml30 f40 fwb">点击授权登录</text>
					</view>
					<view class="wdmaintr oh f1 ml20 c000" v-if="wrap.id">
						<view class="f40 thd fwb">{{wrap.nickname ? wrap.nickname : ''}}</view>
						<view class="mt5 f30 c666">{{wrap.mobile ? wrap.mobile : '未绑定手机号'}}</view>
					</view>
				</view>

				<!-- 个人资料 -->
				<navigator hover-class="none" url="/pages/my/data" class="wsn c999 f30" v-if="wrap.id">
					<text>个人资料</text>
					<uni-icons type="arrowright" color="#999"></uni-icons>
				</navigator>
			</view>

			<!-- 个人中心区 -->
			<view class="area df dfsa aic mt50 pt50 pb40">

				<!-- 账户余额 -->
				<view class="item df dfc aic" @click="link('/pages/my/money')">
					<view class="img wh50">
						<image src="/static/mine1.png" mode="aspectFit"></image>
					</view>
					<view class="txt mt10 c333 f28">账户余额</view>
				</view>

				<!-- 推销管理 -->
				<view hover-class="none" @click="link('/pages/my/setting/setting')" class="item df dfc aic">
					<view class="img wh50">
						<image src="/static/mine2.png" mode="aspectFit"></image>
					</view>
					<view class="txt mt10 c333 f28">推销管理</view>
				</view>

				<!-- 我的收藏 -->
				<view hover-class="none" @click="link('/pages/my/collect')" class="item df dfc aic">
					<view class="img wh50">
						<image src="/static/mine3.png" mode="aspectFit"></image>
					</view>
					<view class="txt mt10 c333 f28">我的收藏</view>
				</view>

				<!-- 商家中心 -->
				<view class="item df dfc aic" @click="toShop">
					<view class="img wh50">
						<image src="/static/mine4.png" mode="aspectFit"></image>
					</view>
					<view class="txt mt10 c333 f28">商家中心</view>
				</view>

			</view>
		</view>

		<!-- 我的订单 -->
		<view class="mOrder area mlr30 plr30">
			<!-- 标题 -->
			<view class="title rows ptb20 bdb1sE">
				<view class="txt c333 f30">我的订单</view>
				<view class="icon">
					<uni-icons type="arrowright" color="#404e60"></uni-icons>
				</view>
			</view>
			<!-- 内容 -->
			<view class="wrap df dfsa aic pt50 ptb30 f26">
				<!-- 全部订单 -->
				<view @click="link('/pages/my/order/order?type=1')" class="list df dfc aic">
					<view class="img wh50">
						<image src="/static/order1.png" mode="aspectFit"></image>
						<view class="script">
							{{num}}
						</view>
					</view>
					<view class="txt mt10">全部订单</view>
				</view>

				<!-- 待付款 -->
				<view @click="link('/pages/my/order/order?type=2')" class="list df dfc aic">
					<view class="img wh50">
						<image src="/static/order2.png" mode="aspectFit"></image>
						<view class="script">
							{{num1}}
						</view>

					</view>
					<view class="txt mt10">待付款</view>
				</view>

				<!-- 待发货 -->
				<view @click="link('/pages/my/order/order?type=3')" class="list df dfc aic">
					<view class="img wh50">
						<image src="/static/order3.png" mode="aspectFit"></image>
						<view class="script">
							{{num2}}
						</view>
					</view>
					<view class="txt mt10">待发货</view>
				</view>

				<!-- 待收货 -->
				<view @click="link('/pages/my/order/order?type=4')" class="list df dfc aic">
					<view class="img wh50">
						<image src="/static/order4.png" mode="aspectFit"></image>
						<view class="script">
							{{num3}}
						</view>
					</view>
					<view class="txt mt10">待收货</view>
				</view>

				<!-- 已完成 -->
				<view @click="link('/pages/my/order/order?type=5')" class="list df dfc aic">
					<view class="img wh50">
						<image src="/static/order5.png" mode="aspectFit"></image>
						<view class="script">
							{{num4}}
						</view>
					</view>
					<view class="txt mt10">已完成</view>
				</view>
			</view>
		</view>

		<!-- 我的nav开始 -->
		<view class="wdmainb mt30">
			<view class="mlr30 bw br20">
				<view class="mlr30 c333 f32 lh100">
					<!-- 承销推广 -->
					<view class="li bdb1sE df dfsb aic pr" @click="navli(4)">
						<view class="libiao df aic">
							<view class="wh40">
								<image class="" src="/static/my4.png"></image>
							</view>
							<view class="pl30 f30 ">承销推广</view>
						</view>
						<icons type="right" color="#333333"></icons>
					</view>
					<!-- 在线客服 -->
					<view class="li bdb1sE df dfsb aic pr" @click="link('/pages/my/service')">
						<view class="libiao df aic">
							<view class="wh40">
								<image class="" src="/static/my1.png"></image>
							</view>
							<view class="pl30 f30 ">在线客服</view>
						</view>
						<icons type="right" color="#333333"></icons>
					</view>
					<!-- 平台公告 -->
					<view class="li bdb1sE df dfsb aic" @click="navli(2)">
						<view class="libiao df aic">
							<view class="wh40">
								<image class="" src="/static/my2.png"></image>
							</view>
							<view class="pl30 f30 ">平台公告({{notice}})</view>
						</view>
						<icons type="right" color="#333333"></icons>
					</view>
					<!-- 关于平台 -->
					<navigator hover-class="none" url="/pages/my/imgTxt?type=2" class="li df dfsb aic">
						<view class="libiao df aic">
							<view class="wh40">
								<image class="" src="/static/my3.png"></image>
							</view>
							<view class="pl30 f30 ">关于平台</view>
						</view>
						<icons type="right" color="#333333"></icons>
					</navigator>

				</view>
			</view>
		</view>

		<view class="ptb50"></view>
	</view>
</template>
<script>
	// 设置页面变量
	var that;
	export default {
		// 页面变量
		data() {
			return {
				// 是否登录
				is_login: false,
				// 内容
				wrap: {},
				num: 0,
				num1: 0,
				num2: 0,
				num3: 0,
				num4: 0,
				notice:0,
			}
		},

		// 获取后
		onLoad() {
			that = this;
		},

		// 显示后
		onShow() {
			// 获取用户信息
			that.getuserinfo();
			that.getordernum()
			this.getnoticenum()
			// that.openMsg()
			if (uni.getStorageSync('token') != '') {
				// const value = uni.getStorageSync('first');
				// if (value) {
				// 	// 如何已经有，直接去home首页
				// 	return
				// } else {
				// 	// 没有值，跳到引导页，并存储，下次打开就不会进去引导页
				// that.openMsg()
				// 	setTimeout(function() {
				// 		uni.setStorage({
				// 			key: 'first',
				// 			data: true
				// 		});
				// 	}, 2000)
				// }

			}
		},

		// 方法列表
		methods: {

			//获取订单表头数据


			getordernum() {
				console.log(2);
				var that = this
				// 请求接口
				that.request({
					url: '/api/index/ordernum',
					// 上传数据
					data: {
						token: uni.getStorageSync('token'),
					},
					// 调用成功
					success(rs) {
						// 返回成功
						if (rs.code == 1) {
							console.log(rs);
							that.num = rs.data[0]
							that.num1 = rs.data[1]
							that.num2 = rs.data[2]
							that.num3 = rs.data[3]
							that.num4 = rs.data[4]
						}
					}
				})
			},
			getnoticenum() {
				var that = this
				// 请求接口
				that.request({
					url: '/api/index/notice',
					// 调用成功
					success(rs) {
						// 返回成功
						if (rs.code == 1) {
							console.log(rs);
						that.notice=rs.data
						}
					}
				})
			},


			// 获取用户信息
			getuserinfo() {
				// 判断有无token
				if (!uni.getStorageSync('token')) {
					// 清空
					that.wrap = {};
					return;
				};

				// 获取用户信息
				that.util.getuserinfo((rs) => {
					that.wrap = rs.data.userinfo;

					// 判断有无手机号
					if (!that.wrap.mobile) {
						// 跳转页面
						uni.navigateTo({
							url: '/pages/my/binding?into=1',
						})
					}
				}, !that.wrap)
			},

			// 跳转
			link(url) {
				// 判断有无登录
				if (!uni.getStorageSync('token')) {
					// 弹窗提示
					that.alert('请先登录');

					return;
				}

				// 跳转页面
				uni.navigateTo({
					url: url,
				})
			},

			// 跳转商城
			toShop() {
				// 入驻状态
				var type = '';
				var url = '/pages/my/shop/shop';

				// 判断入驻状态 1=未申请,2=待审核,3=已通过,4=已驳回
				if (that.wrap.shop_status != 3) {
					url += '?type=' + that.wrap.shop_status;
				} else if (that.wrap.shop_status == 3) {
					// 判断付款  1=无需付款,2=未付款,3=已付款
					if (that.wrap.shop_pay == 2) {
						url += '?type=' + that.wrap.shop_status;
					} else {
						url = '/pages/my/shop/center';
					}
				}
				console.log(url);

				// 跳转页面
				uni.navigateTo({
					url: url,
				})
			},

			navli(e) {
				// 在线客服
				if (e == 1) {
					uni.navigateTo({
						url: '/pages/my/service',
					})
					return
				}
				// 平台公告
				if (e == 2) {
					uni.navigateTo({
						url: '/pages/my/Notice',
					})
					return
				}
				// 关于平台
				if (e == 3) {
					uni.navigateTo({
						url: '/pages/my/Noticedatails?title=' + '关于平台',
					})
					return
				}
				if (e == 4) {
					// 跳转页面
					uni.navigateTo({
						url: '/pages/my/imgTxt?type=1',
					})
				}
			},
			openMsg() {
				// 这里是获取下发权限地方，根据官方文档，可以根据  wx.getSetting() 的 withSubscriptions   这个参数获取用户是否打开订阅消息总开关。后面我们需要获取用户是否同意总是同意消息推送。所以这里要给它设置为true 。
				wx.getSetting({
					withSubscriptions: true, //  这里设置为true,下面才会返回mainSwitch
					success: function(res) {
						console.log('用户统一的', res.subscriptionsSetting.itemSettings);
						// 调起授权界面弹窗
						if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
							// 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
										wx.requestSubscribeMessage({ // 调起消息订阅界面
											tmplIds: [
												'Q6wZlMPfo53p4ujdYan4W8L67iDe-AukzQbZm_ey5mQ',
												'tEw5XboM7JQYu7YXGhn6glwAtfE1TT_4UU-Wo5ckiU8',
												'zBXQg47ZqLZ_le0R9dqb-sa6KnU61RVizo6D4YJYhYE'
											], //收到合作  //解除合作   
											success(res) {
												console.log('订阅消息 成功 ');
												console.log(res);
											},
											fail(er) {
												console.log("订阅消息 失败 ");
												console.log(er);
											}
										})


						} else {
							console.log('订阅消息未开启')
						}
					},
					fail: function(error) {
						console.log(error);
					},
				})
			},
			//login
			login() {
				// 判断是否登录
				if (!uni.getStorageSync('token')) {
					// 跳转页面
					uni.navigateTo({
						url: '/pages/login',
					})
				};
			},

		},
	}
</script>
<style>
	/* 顶部 */
	.wdmaintb {
		height: 410rpx;
		background: linear-gradient(180deg, #FFF7CC 0%, #F6F7F8 100%);
	}

	.img {
		position: relative;
	}

	.script {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
		background-color: red;
		color: #fff;
		height: 30rpx;
		line-height: 30rpx;
		padding: 0 8rpx;
		font-size: 20rpx;
		border-radius: 50%;
	}
</style>
